from typing import List
from fastapi import APIRouter, Body, Depends, Request
from fastapi.routing import APIRoute

from app.api.admin.schema.goods.goods import GoodsCateInSchema, GoodsDeleteInSchema, GoodsDetailInSchema, GoodsInSchema, GoodsOutSchema
from app.api.admin.service.goods.goods import GoodsService
from app.utils.res import unified_resp


goods = APIRouter(prefix="/goods", tags=["商品管理"])


@goods.post("/list")
@unified_resp
async def list(goods_service: GoodsService = Depends(GoodsService.instance)):
    return await goods_service.list()


@goods.post("/add")
@unified_resp
async def add(goods: GoodsInSchema, goods_service: GoodsService = Depends(GoodsService.instance)):
    # print(goods)
    return await goods_service.add(goods)


# @goods.get("/detail/{goods_id}", response_model=GoodsOutSchema)
@goods.get("/detail/{goods_id}")
@unified_resp
async def detail(goods_id: int, goods_service: GoodsService = Depends(GoodsService.instance)):
    print("detail is run")
    return await goods_service.detail(goods_id)


@goods.post("/delete")
@unified_resp
async def delete(del_in: GoodsDeleteInSchema, goods_service: GoodsService = Depends(GoodsService.instance)):
    return await goods_service.delete(del_in.id)


@goods.post("/edit/{goods_id}")
@unified_resp
async def edit(goods_id: int, goods: GoodsInSchema, goods_service: GoodsService = Depends(GoodsService.instance)):
    return await goods_service.edit(goods_id, goods)


@goods.post("/cate_list")
@unified_resp
async def cate_list(goods_cate_service: GoodsService = Depends(GoodsService.instance)):
    return await goods_cate_service.cate_list()


@goods.post("/cate_add")
@unified_resp
async def cate_add(goods_cate_in: GoodsCateInSchema, goods_cate_service: GoodsService = Depends(GoodsService.instance)):
    return await goods_cate_service.cate_add(goods_cate_in)


@goods.post("/cate_delete")
@unified_resp
async def cate_delete(goods_cate_id: int, goods_cate_service: GoodsService = Depends(GoodsService.instance)):
    return await goods_cate_service.cate_delete(goods_cate_id)
